'use strict';

var headers ={
	'Content-Type': 'application/x-www-form-urlencoded'
	// ,'X-Requested-With':'application/x-www-form-urlencoded,text/javascript'
}

angular.module('app.services',['ngResource'])

.factory('Lists',['$resource',function($resource){
	var list = {};
	var listOne = {};
	var msg = {};


	var baseUrl = "http://192.168.0.78/bocms/mobileserver/index.php";
	// var baseUrl = "http://192.168.0.78:220/mobileserver/index.php";

	var listRe = $resource(baseUrl+'/lists/index/27/:page', {page:'@page'});

	var createRe = $resource(baseUrl+'/lists/create?c=:cid', {cid:27},{
		'save':	 {method:'POST',headers: headers}
	});

	var editRe = $resource(baseUrl+'/lists/edit/:id?c=:cid', {id:'@id',cid:27},{
		'get':		{method:'GET'},
		'save':	 {method:'POST',headers: headers}
	});

	var delRe = $resource(baseUrl+'/lists/delete?c=:cid&ids=:id', {id:'@id',cid:27},{
		'del':{method:'GET'}
	});

	return{
		list:function(page){
			if (page == undefined) {
				list = listRe.get()
			}else{
				list = listRe.get({page:page});
			};
			return list;
		}
		,one:function(id) {
			listOne = editRe.get({id:id,cid:27});
			return listOne;
		}
		,create:function(data){
			msg = createRe.save({cid:data.cid},data);
			return msg;
		}
		,save:function(data){
			msg = editRe.save({id:data.id,cid:data.cid},data);
			return msg;
		}
		,del:function(id){
			msg = delRe.del({id:id});
			return msg;
		}
	};
}])



;
